Direct query optimization